<?php require app_path()."/admin/view/common/header.html"?>

<div style="margin:0 15px 15px 15px;">
<el-card shadow="never" style="min-height:650px;">
<div v-if="search_visible" id="search" class="search">
	<el-form ref="form" size="small" :model="searchData" inline>
		<el-form-item label="类型">
			<el-select style="width:150px" v-model="searchData.type" filterable clearable placeholder="请选择">
				<el-option key="0" label="阿里云" value="aly"></el-option>
				<el-option key="1" label="百度飞浆" value="paddlespeech"></el-option>
				<el-option key="2" label="讯飞" value="xunfei"></el-option>
			</el-select>
		</el-form-item>
		<el-form-item label="appkey">
			<el-input id="appkey" v-model="searchData.appkey"  style="width:150px;" placeholder="请输入appkey"></el-input>
		</el-form-item>
		<el-form-item label="url">
			<el-input id="url" v-model="searchData.url"  style="width:150px;" placeholder="请输入url"></el-input>
		</el-form-item>
		<el-form-item label="name">
			<el-input id="name" v-model="searchData.name"  style="width:150px;" placeholder="请输入name"></el-input>
		</el-form-item>
		<search-tool :page_data.sync="page_data" :search_data.sync="searchData" @refesh_list="index"></search-tool>
	</el-form>
</div>
<div class="btn-group" style="margin-top:10px;margin-bottom:10px;">
	<div>
		<el-button v-for="item in button_group" :key="item.access" v-if="checkPermission(item.access,'<?=implode(',',session('admin.access'))?>','<?=session('admin.role_id')?>',[1])" :disabled="$data[item.disabled]" :type="item.color" size="mini" :icon="item.icon" @click="fn(item.clickname)">
			<span v-if="item.batch" v-text="$data['batchUpdateStatus']?'批量保存':'批量编辑'"></span>
			<span v-else v-text="item.name"></span>
		</el-button>
	</div>
	<div><table-tool tableid="typestt" :search_visible.sync="search_visible"   @refesh_list="index"></table-tool></div>
</div>
<el-table id="typestt" :row-class-name="rowClass" @selection-change="selection"  @row-click="handleRowClick"  row-key="typestt_id"  :header-cell-style="{ background: '#eef1f6', color: '#606266' }" @sort-change='sortChange' v-loading="loading"  ref="multipleTable" border class="eltable" :data="list"  style="width: 100%">
	<el-table-column align="center" type="selection" width="42"></el-table-column>
	<el-table-column align="center" type = '' property="typestt_id"  label="编号"  width="70">
	</el-table-column>
	<el-table-column align="center"  property="type"  label="类型" show-overflow-tooltip width="">
		<template slot-scope="scope">
			<el-tag type="primary" v-if="scope.row.type == 'aly'" size="mini" effect="dark">阿里云</el-tag>
			<el-tag type="success" v-if="scope.row.type == 'paddlespeech'" size="mini" effect="dark">百度飞浆</el-tag>
			<el-tag type="info" v-if="scope.row.type == 'xunfei'" size="mini" effect="dark">讯飞</el-tag>
		</template>
	</el-table-column>
	<el-table-column align="center"  property="appkey"  label="appkey" show-overflow-tooltip width="">
	</el-table-column>
	<el-table-column align="center"  property="url"  label="url" show-overflow-tooltip width="">
	</el-table-column>
	<el-table-column align="center"  property="name"  label="name" show-overflow-tooltip width="">
	</el-table-column>
	<el-table-column :fixed="ismobile()?false:'right'" label="操作" align="center" width="190">
		<template slot-scope="scope">
			<div v-if="scope.row.typestt_id">
				<el-button v-if="checkPermission('/admin/Speech/TypeStt/update','<?=implode(",",session("admin.access"))?>','<?=session("admin.role_id")?>',[1])" size="mini" icon="el-icon-edit" type="primary" @click="update(scope.row)" >修改</el-button>
				<el-button v-if="checkPermission('/admin/Speech/TypeStt/delete','<?=implode(",",session("admin.access"))?>','<?=session("admin.role_id")?>',[1])" size="mini" icon="el-icon-delete" type="danger" @click="del(scope.row)" >删除</el-button>
			</div>
		</template>
	</el-table-column>
</el-table>
<Page :total="page_data.total" :page.sync="page_data.page" :limit.sync="page_data.limit" @pagination="index" />
</el-card>

<!--添加-->
<Add :show.sync="dialog.addDialogStatus" size="small" @refesh_list="index"></Add>
<!--修改-->
<Update :info="updateInfo" :show.sync="dialog.updateDialogStatus" size="small" @refesh_list="index"></Update>
<!--查看详情-->
<Detail :info="detailInfo" :show.sync="dialog.detailDialogStatus" size="small" @refesh_list="index"></Detail>

</div>

<?php require app_path()."/admin/view/common/foot.html"?>

<script src="/assets/js/app.js"></script>
<script src="/components/admin/speech/typestt/add.js?v=<?php echo rand(1000,9999)?>"></script>
<script src="/components/admin/speech/typestt/update.js?v=<?php echo rand(1000,9999)?>"></script>
<script src="/components/admin/speech/typestt/detail.js?v=<?php echo rand(1000,9999)?>"></script>
<script>
new Vue({
	el: '#app',
	components:{
	},
	data: function() {
		return {
			dialog: {
				addDialogStatus : false,
				updateDialogStatus : false,
				detailDialogStatus : false,
			},
			searchData:{},
			button_group:[
				{name:'添加',color:'success',access:'/admin/Speech/TypeStt/add',icon:'el-icon-plus',disabled:'',clickname:'add'},
				{name:'修改',color:'primary',access:'/admin/Speech/TypeStt/update',icon:'el-icon-edit',disabled:'single',clickname:'update'},
				{name:'删除',color:'danger',access:'/admin/Speech/TypeStt/delete',icon:'el-icon-delete',disabled:'multiple',clickname:'del'},
				{name:'查看详情',color:'info',access:'/admin/Speech/TypeStt/detail',icon:'el-icon-view',disabled:'single',clickname:'detail'},
			],
			loading: false,
			page_data: {
				limit: 20,
				page: 1,
				total:20,
			},
			order:'',
			sort:'',
			ids: [],
			single:true,
			multiple:true,
			search_visible:true,
			list: [],
			updateInfo:{},
			detailInfo:{},
		}
	},
	methods:{
		index(){
			let param = {limit:this.page_data.limit,page:this.page_data.page,order:this.order,sort:this.sort}
			Object.assign(param, this.searchData,this.urlobj)
			this.loading = true
			axios.post(base_url + '/Speech/TypeStt/index',param).then(res => {
				if(res.data.status == 200){
					this.list = res.data.data.data
					this.page_data.total = res.data.data.total
					this.loading = false
				}else{
					this.$message.error(res.data.msg);
				}
			})
		},
		updateExt(row,field){
			if(row.typestt_id){
				axios.post(base_url + '/Speech/TypeStt/updateExt',{typestt_id:row.typestt_id,[field]:row[field]}).then(res => {
					if(res.data.status == 200){
						this.$message({message: res.data.msg, type: 'success'})
					}else{
						this.$message.error(res.data.msg)
					}
				})
			}
		},
		add(){
			this.dialog.addDialogStatus = true
		},
		update(row){
			let id = row.typestt_id ? row.typestt_id : this.ids.join(',')
			axios.post(base_url + '/Speech/TypeStt/getUpdateInfo',{typestt_id:id}).then(res => {
				if(res.data.status == 200){
					this.dialog.updateDialogStatus = true
					this.updateInfo = res.data.data
				}else{
					this.$message.error(res.data.msg)
				}
			})
		},
		del(row){
			this.$confirm('确定操作吗?', '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning'
			}).then(() => {
				let ids = row.typestt_id ? row.typestt_id : this.ids.join(',')
				axios.post(base_url + '/Speech/TypeStt/delete',{typestt_id:ids}).then(res => {
					if(res.data.status == 200){
						this.$message({message: res.data.msg, type: 'success'})
						this.index()
					}else{
						this.$message.error(res.data.msg)
					}
				})
			}).catch(() => {})
		},
		detail(row){
			this.dialog.detailDialogStatus = true
			this.detailInfo = {typestt_id:row.typestt_id ? row.typestt_id : this.ids.join(',')}
		},
		selection(selection) {
			this.ids = selection.map(item => item.typestt_id)
			this.single = selection.length != 1
			this.multiple = !selection.length
		},
		handleRowClick(row, rowIndex,event){
			if(event.target.className !== 'el-input__inner'){
				this.$refs.multipleTable.toggleRowSelection(row)
			}
		},
		rowClass ({ row, rowIndex }) {
			for(let i=0;i<this.ids.length;i++) {
				if (row.typestt_id === this.ids[i]) {
					return 'rowLight'
				}
			}
		},
		sortChange(val){
			if(val.order == 'descending'){
				this.order= 'desc'
			}
			if(val.order == 'ascending'){
				this.order= 'asc'
			}
			this.sort = val.prop
			this.index()
		},
		fn(method){
			this[method](this.ids)
		},
	},
	mounted(){
		this.index()
	},
})
</script>
</body>
</html>